﻿#ifndef CAPCONTROLDEFINE_H
#define CAPCONTROLDEFINE_H
#include <qobject.h>
#include <QMap>
#include "define.h"
#pragma pack(1)

#define M_AXIS_AZI 0
#define M_AXIS_PICTH 1
#define M_AXIS_ALL 2


typedef struct _thresholdParam
{
    uchar frame_header=0xC1;
    uchar frame_type=0x11;
    uchar datatype=0x13;
    uchar cmdid = 0x0;//控制参数类型
    uchar data[4]={0};//先高后低 数据字0--位置给定模式下表示前馈控制字，0xAA：表示加入，其他不加入
    uchar rsv0=0;
    uchar rsv1=0;
    uchar rsv2=0;
    uchar rsv3=0;
    uchar checksum=0;

}st_thresholdParam;
Q_DECLARE_METATYPE(st_thresholdParam)



typedef struct _pidframe
{
    uchar frame_header=0xC1;
    uchar frame_type=0x11;
    uchar datatype=0x23;
    uchar cmdid = 0x0;//控制参数类型
    uchar data[4]={0};//先高后低 数据字0--位置给定模式下表示前馈控制字，0xAA：表示加入，其他不加入
    uchar rsv0=0;
    uchar rsv1=0;
    uchar rsv2=0;
    uchar rsv3=0;
    uchar checksum=0;
}st_pid_frame;
Q_DECLARE_METATYPE(st_pid_frame)


typedef struct _groundTestParam
{
    uchar frame_header=0xC1;
    uchar frame_type=0x11;
    uchar datatype=0x33;
    uchar cmdid = 0x0;//控制参数类型
    uchar data1[4]={0};//先高后低
    uchar data2[4]={0};//先高后低
    uchar checksum=0;

}st_groundTestParam;
Q_DECLARE_METATYPE(st_groundTestParam)


typedef struct _statuscode
{
    uchar enablestatus:1;
    uchar CWEnablestatus:1;
    uchar CCWEnableStatus:1;
    uchar rsv:5;
}st_statuscode;

typedef union _un_status
{
    uchar data;
    st_statuscode statuscode;
}un_status;

//测试模式 驱动器实时上传的数据
typedef struct _loopbackdata
{
    uchar frame_header=0xC1;
    uchar frame_type=0x11;
    uchar datatype=0x44;
    short i16CurrentA;//A相电流
    short i16CurrentB;//B相电流
    short i16QSetdata;//Q相指令值
    short i16QRespdata;//Q相反馈值
    short i16Current;//母线电流


    short i16SpeedSetdata;//速度指令值
    short i16SpeedRespdata;//速度反馈值

    int i32PosSetdata;//位置指令值
    int i32PosRespdata;//位置反馈值

    short i16MotorTemplate;//电机温度
    short i16IPMTemplate;//IPM温度

    uchar u8Errcode=0;
    uchar u8Status=0;


    uchar checksum;

}st_loopbackdata;
Q_DECLARE_METATYPE(st_loopbackdata)


typedef struct _unlockcmd
{
    uchar frame_header=0xC1;
    uchar frame_type=0x33;
    unsigned short frame_cnt=0;
    uchar frame_cmdid=0;
    uchar unlocktime=0;//原始数据x10
    uchar rsv[12]={0};
    uchar checksum=0;
}st_unlockcmd;

typedef struct _handshake
{
    uchar frame_header=0xC1;
    uchar frame_type=0x44;
    unsigned short frame_cnt=0;
    uchar azimuth_datatype=0;//0xaa握手 0xfe非方位
    uchar azimuth_workmode=0x2A;//固定值  位置给定模式
    uchar azimuth_rsv0=0;
    uchar azimuth_data[3]={0};//先高后低  数据为24位
    uchar azimuth_rsv1=0;

    uchar pitch_datatype=0;//0xaa握手 0xfe非方位
    uchar pitch_workmode=0x2A;//固定值  位置给定模式
    uchar pitch_rsv0=0;
    uchar pitch_data[3]={0};//先高后低  数据为24位
    uchar pitch_rsv1=0;
    uchar checksum;

}st_handshake;







typedef struct _loopdata_11//轮训指令为0x11时对应的数据
{
    twochar azimuth_speed_cmd_value;//0.01，范围-320°/s~320°/s
    twochar azimuth_speed_response_value;//0.01，范围-320°/s~320°/s
    twochar azimuth_currentQ_cmd_value;//范围-3A~3A，当量0.0001
    twochar azimuth_currentQ_response_value;//范围-3A~3A，当量0.0001

    uchar azimuth_speed_limit;//0.1
    uchar azimuth_overspeed_limit;//0.1 超速保护门限
    uchar azimuth_current_limit;
    uchar azimuth_overcurrent_limit;
    uchar azimuth_acc_limit;

    twochar pitch_speed_cmd_value;//0.01，范围-320°/s~320°/s
    twochar pitch_speed_response_value;//0.01，范围-320°/s~320°/s
    twochar pitch_currentQ_cmd_value;//范围-3A~3A，当量0.0001
    twochar pitch_currentQ_response_value;//范围-3A~3A，当量0.0001

    uchar pitch_speed_limit;//0.1
    uchar pitch_overspeed_limit;//0.1 超速保护门限
    uchar pitch_current_limit;
    uchar pitch_overcurrent_limit;
    uchar pitch_acc_limit;


    uchar FPGAverison;
    uchar DSPversion;
    uchar rsv;

}st_loopdata_11;
Q_DECLARE_METATYPE(st_loopdata_11)

typedef struct _loopdata_55//轮训指令为0x55时对应的数据
{
    uchar azimuth_pos_offset[3];//角位置偏置 无符号 24位 360/16777216
    uchar azimuth_zero_offset[3];//零位偏置 无符号 24位 360/16777216
    uchar azimuth_filter_param[3];//
    uchar azimuth_pos_max_limit;//360/255
    uchar azimuth_pos_min_limit;//360/255
    uchar azimuth_param_checksum;//参数存储区按字节累加和，取低字节，1字节
    uchar rsv;

    uchar pitch_pos_offset[3];//角位置偏置 无符号 24位 360/16777216
    uchar pitch_zero_offset[3];//零位偏置 无符号 24位 360/16777216
    uchar pitch_filter_param[3];//
    uchar pitch_pos_max_limit;//360/255
    uchar pitch_pos_min_limit;//360/255
    uchar pitch_param_checksum;//参数存储区按字节累加和，取低字节，1字节
    uchar rsv1;

    uchar DSP_reset_cnt;
    uchar encoder_status;
    uchar rsv2;

}st_loopdata_55;
Q_DECLARE_METATYPE(st_loopdata_55)


typedef struct _loopdata_AA//轮训指令为0xAA时对应的数据
{
    twochar azimuth_pos_KP;
    twochar azimuth_pos_KI;
    twochar azimuth_pos_KD;

    twochar azimuth_speed_KP;
    twochar azimuth_speed_KI;

    twochar azimuth_current_KP;
    twochar azimuth_current_KI;


    twochar pitch_pos_KP;
    twochar pitch_pos_KI;
    twochar pitch_pos_KD;

    twochar pitch_speed_KP;
    twochar pitch_speed_KI;

    twochar pitch_current_KP;
    twochar pitch_current_KI;


    uchar rsv;

}st_loopdata_AA;
Q_DECLARE_METATYPE(st_loopdata_AA)

typedef struct _loopdata_BB//轮训指令为0xBB时对应的数据
{
    uchar endflag;//电流整定结束标志
    //电机1
    twochar azimuth_rsdata;//电阻 x100
    twochar azimuth_lddata;//电感 x100
    twochar azimuth_lqdata;//电感 x100

    //电机1
    twochar  pitch_rsdata;//电阻 x100
    twochar  pitch_lddata;//电感 x100
    twochar  pitch_lqdata;//电感 x100

    uchar rcv[16];

}st_loopdata_BB;
Q_DECLARE_METATYPE(st_loopdata_BB)

union loopdata
{
    st_loopdata_55 loopdata_55;
    st_loopdata_11 loopdata_11;
    st_loopdata_AA loopdata_AA;
    st_loopdata_BB loopdata_BB;
    uchar data[29];
};
Q_DECLARE_METATYPE(loopdata)


typedef struct _caprcvdata
{
    uchar frame_header;//0xc1
    uchar frame_type;//0x91
    uchar azimuthInfo;//方位遥测信息
    uchar pitchInfo;//俯仰遥测信息

    twochar azimuthcurrent_A;//A相电流 系数0.0001
    twochar azimuthcurrent_C;//C相电流 系数0.0001
    twochar pitchcurrent_A;//A相电流 系数0.0001
    twochar pitchcurrent_C;//C相电流 系数0.0001
    uchar framecnt;//帧计数

    uchar cmdrcvstatus;//指令接收状态
    uchar cmdprocstatus;//指令执行状态
    uchar azimuthcmdcnt;//方位指令计数
    uchar pitchcmdcnt;//俯仰指令计数
    uchar azimuthcmd_value[3];//指令值 无符号 24位 360/16777216
    uchar pitchcmd_value[3];//指令值 无符号 24位 360/16777216

    uchar azimuthresponse_value[3];//反馈值 无符号 24位 360/16777216
    uchar pitchresponse_value[3];//反馈值 无符号 24位 360/16777216

    uchar loopcmd;//轮训指令
    union loopdata loopcmd_data;//轮训数据值

    uchar checksum;

}st_rcvdata;
Q_DECLARE_METATYPE(st_rcvdata)



typedef struct _cmd_attr
{
    QString sName;//命令名称
    int i32Cmdid;
    float lfCoeff;//比例尺
    QString sUnit;//单位
    int i32Valuelen;//数据为占字节数
    bool bsigned = false; //有无符号
    float lfMaxValue;
    float lfMinValue;
    uchar* ptrValue;//

    int i32RowIndex;

    QMap<int,QString> valueMap;

    uchar* ptrParamValue[2];//值指针1 轴1  2-轴2

}st_cmd_attr;



typedef struct _groundtest
{
    uchar frame_header=0xC1;
    uchar frame_type=0x55;
    unsigned short frame_cnt=0;
    uchar azimuth_datatype=0;//0xCC：方位地面测试指令 0xFE：非方位指令
    uchar azimuth_workmode=0;//测试模式
    uchar azimuth_data[4]={0};//先高后低  数据为32位
    uchar rsv1=0;

    uchar pitch_datatype=0;//0xCC：地面测试指令 0xFE：非方位指令
    uchar pitch_workmode=0;//测试模式
    uchar pitch_data[4]={0};//先高后低  数据为32位
    uchar rsv=0;
    uchar checksum=0;

}st_groundtest;

#pragma pack()
#endif // CAPCONTROLDEFINE_
